package my.framework.ssm.sample.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import my.framework.ssm.sample.common.enums.NotifyEnum;
import my.framework.ssm.sample.common.mq.redis.RedisMqSender;
import my.framework.ssm.sample.mapper.UserMapper;
import my.framework.ssm.sample.model.UserVO;
import my.framework.ssm.sample.service.NotifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author NuKi
 * @date 2018/11/24 14:00
 */
@Slf4j
@Service
public class NotifyServiceImpl extends ServiceImpl<UserMapper, UserVO> implements NotifyService {

    @Autowired
    private RedisMqSender redisMqSender;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void notifyMessage(String params, NotifyEnum notifyType) {
        //仅用于示例，在需要保证消息不丢失的情景下不能使用redisMq
        redisMqSender.send(notifyType.getPattenName(), params);
    }

    @Override
    public void sendAll(String message) {
        List<UserVO> allUsers = baseMapper.selectList(null);
        log.info("send massge[{}] to all users==>{}", message, allUsers);
    }
}
